# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Nicolas Leclercq <nicolas.private@gmail.com>
# Contributor: Adam S Levy <adam@aslevy.com>
# Contributor: Charles B. Johnson <mail@cbjohnson.info>
# Contributor: Daichi Shinozaki <dsdseg@gmail.com>
# Contributor: Ben Alex <ben.alex@acegi.com.au>

pkgname=influx-cli
pkgver=2.7.3
_commit_sha=8b962c7
pkgrel=1
pkgdesc='CLI for managing resources in InfluxDB'
arch=('loong64' 'x86_64')
url='https://github.com/InfluxData/influx-cli'
license=('MIT')
makedepends=('go' 'go-tools' 'git')
options=('!lto')
backup=('etc/influxdb/influxdb.conf')
source=("git+https://github.com/influxdata/influx-cli.git#tag=v${pkgver}")
sha256sums=('SKIP')

build(){
  cd "$pkgname"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  export LDFLAGS="-linkmode external"
  PATH="$(go env GOPATH)/bin:$PATH" make VERSION=$pkgver COMMIT=$_commit_sha
}

check(){
  cd "$pkgname"
  PATH="$(go env GOPATH)/bin:$PATH" make test
}

package(){
  cd "$pkgname"
  install -Dm755 bin/linux/amd64/influx -t "$pkgdir/usr/bin"
  install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/${pkgname}"
  bin/linux/influx completion bash | install -Dm644 /dev/stdin "$pkgdir/usr/share/bash-completion/completions/influx-cli"
  bin/linux/influx completion zsh | install -Dm644 /dev/stdin "$pkgdir/usr/share/zsh/site-functions/_influx-cli"
  #bin/linux/influx completion fish | install -Dm644 /dev/stdin "$pkgdir/usr/share/fish/vendor_completions.d/influx-cli.fish"
}
